﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace Utility
{
    public class DoubleBufferListView : ListView
    {
        public DoubleBufferListView():base()
        {
            SetStyle(ControlStyles.DoubleBuffer |
                ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.AllPaintingInWmPaint, true);
            //this.SetStyle(
            //ControlStyles.OptimizedDoubleBuffer
            //| ControlStyles.ResizeRedraw
            //| ControlStyles.Selectable
            //| ControlStyles.AllPaintingInWmPaint
            //| ControlStyles.UserPaint
            //| ControlStyles.SupportsTransparentBackColor,
            //true);
            UpdateStyles();
               
        }

        private void SetDoubleBuffer()
        {
            this.SetStyle(
            ControlStyles.OptimizedDoubleBuffer
            | ControlStyles.ResizeRedraw
            | ControlStyles.Selectable
            | ControlStyles.AllPaintingInWmPaint
            | ControlStyles.UserPaint
            | ControlStyles.SupportsTransparentBackColor,
            true);
        }

        [DllImport("user32.dll")]
        public static extern int ShowScrollBar(IntPtr hWnd, int iBar, int bShow);

        const int SB_HORZ = 0;
        const int SB_VERT = 1;

        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            //if (this.View == View.List)
            //{
                //ShowScrollBar(this.Handle, SB_VERT, 1);
                ShowScrollBar(this.Handle, SB_HORZ, 0);
            //}
            base.WndProc(ref m);
        }

    }
}
